package com.yycwxt.modules.admin.subcompare;

import java.util.Map;

public class SubCompareProvider {
    public String subcomsql(Map<String, Object> map){
        String [] subjects = (String[]) map.get("subject");
//        Integer [] lens = (Integer []) map.get("len");
        String tem = """
                select 
                left((select fullname where code like '%s%%'),locate('-',fullname)-1) '科目总名',
                        (select fullname where code like '%s%%') '科目名称',
                        count(case when subject_name = fullname then 1 end) '累计执行',
                        count(case when shop_name = '天猫-榆园食品专营店' then 1 end) '天猫榆园食品专营店',
                        count(case when shop_name = '淘宝-榆园东北特产店' then 1 end) '淘宝榆园东北特产店',
                        count(case when shop_name = '美团-榆园食品专营店' then 1 end) '美团榆园食品专营店',
                        count(case when shop_name = '抖音-榆园食品专营店' then 1 end) '抖音榆园食品专营店',
                        count(case when shop_name = '天猫-福宁旗舰店' then 1 end) '天猫福宁旗舰店',
                        count(case when shop_name = '抖音-青花美食坊' then 1 end) '抖音青花美食坊',
                        count(case when shop_name = '京东-榆园食品专营店' then 1 end) '京东榆园食品专营店',
                        count(case when shop_name = '快手-榆园食品专营店' then 1 end) '快手榆园食品专营店',
                        count(case when shop_name = '天猫-榆园食品旗舰店' then 1 end) '天猫榆园食品旗舰店',
                        count(case when shop_name = '天猫-青花食品旗舰店' then 1 end) '天猫青花食品旗舰店',
                        count(case when shop_name = '拼多多-榆园调味品专营店' then 1 end) '拼多多榆园调味品专营店',
                        count(case when shop_name = '拼多多-榆园食品专营店' then 1 end) '拼多多榆园食品专营店',
                        count(case when shop_name = '拼多多-榆园调味品专营店' then 1 end) '拼多多榆园调味品专营店',
                        count(case when shop_name = '淘宝-榆园食品特卖店' then 1 end) '淘宝榆园食品特卖店',
                        count(case when shop_name = '拼多多-青花食品旗舰店' then 1 end) '拼多多青花食品旗舰店',
                        count(case when shop_name = '淘宝-青花食品特卖店' then 1 end) '淘宝青花食品特卖店',
                        count(case when shop_name = '微信小商店' then 1 end) '微信小商店',
                        count(case when shop_name = '京东-昊七食品专营店' then 1 end) '京东昊七食品专营店',
                        count(case when shop_name = '抖音-昊七七食品旗舰店' then 1 end) '抖音昊七七食品旗舰店'
                        from yycwxt_test.core_flows join yycwxt_test.core_subject on code = subject_code
                        where subject_code like '%s%%'
                        group by 科目总名, 科目名称
                """;
       String a = """
               union 
               """ ;
        StringBuilder sql = new StringBuilder();
        for (int i = 0; i < subjects.length; i++) {
            sql.append(String.format(tem, subjects[i], subjects[i], subjects[i]));
            if (i<subjects.length-1){
                sql.append(a);
            }
        }
        return sql.toString();
    }
}
